<?php
class Catalog extends AppModel {

	var $name = 'Catalog';
	var $primaryKey = 'catalog_id';

   /**
    * Creating catalog data
    * usage in : Post Controller -> function upload()
    */
   public function createData($id){
      $this->recursive = -1;
      $this->create();
      $this->data['Catalog']['post_id'] = $id;
      $this->data['Catalog']['created'] = date('Y-m-d H:i:s');
      $this->save($this->data);

      return ($this->id);
   }

   /**
    * Updating catalog data
    * usage in : Posts Controller -> function saveDraft(), savePost()
    */
   public function updateData($post_id,$title,$category_id,$category,$tags,$description){
      $this->recursive = -1;
      $this->updateAll(
            array('Catalog.status'=>'1','Catalog.title' => "'$title'",'Catalog.category_id'=>"'$category_id'",'Catalog.category'=>"'$category'",'Catalog.tag'=>"'$tags'",'Catalog.description'=>"'$description'"),
            array('Catalog.post_id' =>$post_id)
        );
   }

   /**
    * Searching related Logo
    * usage in : Post Controller -> function view ()
    */
   public function getRelated($category_id,$tag,$post_id){
      $getByCategory = $this->find('list',array(
            'conditions'=>array('AND'=>array('Catalog.category_id'=>$category_id,'Catalog.status'=>'1','NOT'=>array('Catalog.post_id'=>$post_id))),
            'fields'=>'Catalog.post_id')
       );

       $getByTag = $this->find('list',array(
            'conditions'=>array('AND'=>array('Catalog.post_id'=>$getByCategory,"MATCH(Catalog.tag) AGAINST('$tag' IN BOOLEAN MODE)")),
            'fields'=>'Catalog.post_id')
       );
       
       return array($getByCategory,$getByTag);
   }
}

?>